package com.yunfeng.supercall.activity;

import org.json.JSONException;
import org.json.JSONObject;

import android.os.Bundle;

import com.yunfeng.supercall.R;
import com.yunfeng.supercall.httputils.MyAjaxCallBack;

/**
 * 创建组后将好友拉入组
 * 
 * @author 洋
 * 
 */
public class CreateGroupAddFriendsActivity extends
		CreateCirlcleAddFriendActivity {

	private int mGroupId;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		mGroupId = getIntent().getIntExtra(KEY_OTHER_ID, 0);
	}

	@Override
	public void add() {
		StringBuilder sb = new StringBuilder();
		for (int j = mChoice.length, i = 0; i < j; i++) {
			if (mChoice[i]) {
				sb.append(mList.get(i).getUserid());
				sb.append(";");
			}
		}
		if (!sb.toString().isEmpty()) {
			sb.deleteCharAt(sb.length() - 1);
		}

		JSONObject json = getBaseParams(getActivity());
		try {
			json.put("i_friendid", sb.toString());
			json.put("i_groupid", mGroupId);
			showProgressDialog(R.string.adding);
		} catch (JSONException e) {
			e.printStackTrace();
		}
		mHttpClient.post(FUNCTION_JOIN_GROUP, json, new MyAjaxCallBack() {

			@Override
			public void onReceiveError(String msg, String errorCode) {
				showToast(msg);
				cancelProgressDialog();
			}

			@Override
			public void onReceiveData(String data, String msg) {
				showToast(R.string.add_success);
				cancelProgressDialog();
				finish();
			}
		});
	}
}
